//
//  LPZWYMYTestTableViewCell.m
//  ZhongWangYuan
//
//  Created by liuyingping on 2018/6/2.
//  Copyright © 2018年 ZJ. All rights reserved.
//

#import "LPZWYMYTestTableViewCell.h"

@interface LPZWYMYTestTableViewCell ()
/**    */
@property (strong, nonatomic) UILabel  *titleLabel;
/**    */
@property (strong, nonatomic) UILabel  *redLabel;
/**    */
@property (strong, nonatomic) UILabel  *hintLabel;
/**    */
@property (strong, nonatomic) UIButton  *button;


@end
@implementation LPZWYMYTestTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self layoutUI];
    }
    return self;
}

// 85
- (void)layoutUI{
    [self addSubview:self.titleLabel];
    [self addSubview:self.redLabel];
    [self addSubview:self.hintLabel];
    [self addSubview:self.button];
    
    self.redLabel.sd_layout
    .centerYEqualToView(self)
    .heightIs(15 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 15 * [UIScreen zj_screenWScale])
    .widthIs([UIScreen zj_screenWith] * 0.5);
    
    self.titleLabel.sd_layout
    .bottomSpaceToView(self.redLabel, 10 * [UIScreen zj_screenHScale])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.redLabel)
    .widthIs([UIScreen zj_screenWith] - 93 * [UIScreen zj_screenWScale]);
    
    self.hintLabel.sd_layout
    .topSpaceToView(self.redLabel, 10 * [UIScreen zj_screenHScale])
    .heightIs(15 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.redLabel)
    .widthIs([UIScreen zj_screenWith] - 93 * [UIScreen zj_screenWScale]);
    
    self.button.sd_layout
    .centerYEqualToView(self)
    .heightIs(40 * [UIScreen zj_screenHScale])
    .rightSpaceToView(self, 10 * [UIScreen zj_screenWScale])
    .widthIs(65 * [UIScreen zj_screenWScale]);
    
    
    UIView *under = [UIView new];
    under.backgroundColor = [UIColor themeGrayColor];
    [self addSubview:under];
    under.sd_layout.leftEqualToView(self).bottomEqualToView(self).widthIs([UIScreen zj_screenWith]).heightIs(1);
    
    
}

- (void)setModel:(LPZWYMYTestModel *)model{
    _model = model;
    self.titleLabel.text = model.classname;
    self.redLabel.text = [NSString stringWithFormat:@"已看完%@%%",model.studyrate];
    self.hintLabel.text = @"学习时长未满足不能进行考试";
    if ([model.studyrate integerValue] == 100) {
        self.button.userInteractionEnabled = YES;
        [self.button setTitleColor:[UIColor themeColor] forState:UIControlStateNormal];
    }else{
        self.button.userInteractionEnabled = YES;
         [self.button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    }
}


- (void)clickButton{
    if (self.delegate) {
        [self.delegate LPZWYMYTestTableViewCell_click_section:self.section row:self.row];
    }
}


#pragma mark - setter
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor textBlackColor];
        _titleLabel.font = LYPFONT(17);
    }
    return _titleLabel;
}


- (UILabel *)redLabel{
    if (!_redLabel) {
        _redLabel = [UILabel new];
        _redLabel.textColor = [UIColor themeColor];
        _redLabel.font = LYPFONT(13);
    }
    return _redLabel;
}


- (UILabel *)hintLabel{
    if (!_hintLabel) {
        _hintLabel = [UILabel new];
        _hintLabel.textColor = [UIColor lightGrayColor];
        _hintLabel.font = LYPFONT(13);
    }
    return _hintLabel;
}


- (UIButton *)button{
    if (!_button) {
        _button = [UIButton new];
        _button.backgroundColor = [UIColor zj_colorWithHexString:@"ebebeb"];
        _button.layer.cornerRadius = 20;
        _button.layer.masksToBounds = YES;
        _button.titleLabel.font = LYPFONT(14);
        [_button setTitle:@"考试" forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(clickButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

@end
